package view.content;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.io.File;

import javax.swing.SwingUtilities;

import model.contents.Content;
import platform.Platform;
import chrriis.dj.nativeswing.swtimpl.components.JWebBrowser;

public class BrowserBox extends ContentBox {
	private Content content;
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public BrowserBox(Content content, int width, int height) {
		super(content, width, height);
		this.content = content;
		
		Platform.getPlatform().toString();
		
		System.out.println("Width = "+width);
		System.out.println("height = "+height);

		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				initialization();	
			}});
	}

	private void initialization()
	{
		
		JWebBrowser webBrowser = new JWebBrowser();
		String abpath = getAbsolutePath(content.getLocalPath());
		webBrowser.navigate(abpath);
		this.setLayout(new BorderLayout());
		this.setPreferredSize(new Dimension(this.width,this.height));
		webBrowser.setMenuBarVisible(false);
		webBrowser.setBarsVisible(false);
		webBrowser.setAutoscrolls(false);
		webBrowser.setStatusBarVisible(false);
		//webBrowser.setMaximumSize(new Dimension(1000,1000));
		add(webBrowser,BorderLayout.CENTER);
		//webBrowser.setSize(width, 1000);
		System.out.println("Browser is playing");
	}

	private String getAbsolutePath(String filepath)
	{
		File file = new File(filepath);
		String absolutePathOfFirstFile = file.getAbsolutePath();
		return absolutePathOfFirstFile;
	}

}